package overrideoverwrite;

/**
 * @ClassName Overwrite
 * @Date 2024/11/5 20:42 07
 * @Author Jack Chen
 * @Description
 * @Version 1.0
 */

public class Overwrite {
    public static void main(String[] args) {
        // Overwirte
        /**
         * overwrite mains to re-write the method
         *  with the same name of method, but different parameters
         */
        eat();
        eat(11);
        eat("Jack Chen");
        eat("Jack Chen", 13);
        eat("Jack Chen", 13, 3);

        // Override and Dynamic binding and polymorphic-多态
        /**
         * 在代码运行时，当传递不同类对象时，会调用对应类中的方法
         * 同一个事情，不同的对象来做，产生的结果不同，这就是“多态”
         */
        Animal animal = new Animal("小动物");   // 父类对象
        Dog dog = new Dog("小狗");  // 子类对象
        Cat cat = new Cat("小猫");  // 子类对象
        voice(animal);  // 传入父类对象
        voice(dog);  // 传入子类对象
        voice(cat);
    }

    public static void voice(Animal animal) { // 父类的变量的引用
        animal.voice();
    }

    public static void eat(int num) {
        System.out.println("eat " + num + " apples");
    }

    public static void eat(String name) {
        System.out.println(name + " eat apples");
    }

    public static void eat(String name, int num) {
        System.out.println(name + " eat apples " + num);
    }

    public static void eat() {
        System.out.println("eat apples");
    }

    public static void eat(String name, int num, int num2) {
        System.out.println(name + " eat " + num + " apples and give jack " + num2 + " apples");

    }
//    Can not set the same name of method and parameter but different return, not allowed
//    public static String eat() {
//        return null;
//    }

}
